/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 *
 */

import { getOsLanguage } from '@ohos/hvigor-common';

import { getJson5Obj } from './json-util.js';

/**
 * 读取报错的url, url存在res目录下的error.json中
 */
export class ErrorUrl {
  // 目前只有一条url, 直接读取, 后续如果有新增的考虑使用缓存
  public static readonly ERROR_URL: { [key: string]: string } = getErrorUrl();
}

function getErrorUrl() {
  const errorJson = getJson5Obj(`${__dirname}/../../res/error/error.json`);
  const country = getOsLanguage();
  const keys = Object.keys(errorJson);
  return keys.reduce((urlObj, key) => {
    return { ...urlObj, [key]: errorJson[key][country] };
  }, {});
}
